import java.util.Arrays;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        final PaperList listOfRainy = new PaperList("Rainy",
                Arrays.asList(
                        new Thesis("Science"),
                        new ConferencePaper("Science"),
                        new JournalPaper("Technology"),
                        new Thesis("Computer Science"),
                        new JournalPaper("Art")
                )
        );

        final List<Student> students = Arrays.asList(
                new Student("Cloudy", 1, PaperType.Thesis),
                new Student("Sunny", 1, PaperType.JournalPaper),
                new Student("Windy", 2, PaperType.Any),
                new Student("Snowy", 1, PaperType.ConferencePaper)
        );

        for (Student student : students) {
            new Thread(() -> {
                try {
                    List<Paper> selected = listOfRainy.selectPaperByRandom(student);
                    if (selected != null) {
                        System.out.println(student.getName() + " 成功选择论文: " + selected);
                    }
                } catch (NoEnoughPapersException e) {
                    System.err.println(e.getMessage());
                }
            }).start();
        }

        try {
            Thread.sleep(1000);
            StudentCountVisitor visitor = new StudentCountVisitor();
            listOfRainy.getSelectionResult().accept(visitor);
            System.out.println("已选择论文的学生数量: " + visitor.getStudentCount());
            System.out.println("所有选择结果: " + listOfRainy.getSelectionResult().getSelections());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}    